package com.management.controller;

import com.management.po.Company;
import com.management.po.User;
import com.management.service.CompanyService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author ls
 * @category
 * 系统公司管理控制器
 */
@Controller
public class SCompanyController {
    Logger logger = Logger.getLogger(SCompanyController.class);
    @Resource
    CompanyService companyService;
    @RequestMapping("/System/companylist")
    public String companyList(Model model){
        logger.info("进入了公司列表控制器");
        List<Company> list = companyService.findAll();
        model.addAttribute("list",list);
        return "companylist";
    }
    @RequestMapping("/System/toadd")
    public String toadd(){
        logger.info("进入了去添加公司控制器");
        return "add";
    }
    @RequestMapping("/System/add")
    public String add(Company company, HttpSession session){
        Object obj = session.getAttribute("currentUser");
        User user = (User)obj;
        int userId = user.getUserId();
        logger.info("进入添加公司控制器");
        logger.info(company);
       int i = companyService.add(company);
       logger.info(i);
       return "redirect:main.action?userId="+userId;

    }
   /* @RequestMapping("/System/toupdate")
    public String toupdate(){
        logger.info("进入了去修改控制器");
        return "updatecompany";
    }
    @RequestMapping("/System/update")
    public String update(Company company){
        logger.info("进入了修改控制器");
      int i =  companyService.update(company);
      logger.info(i);
      return "redirect:/System/companylist.action";
    }*/
}
